#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "Calendar/Calendar.h"
#include "Chat/chat.h"
#include "IdeaBox/ideabox.h"
#include "Protocol/msgheader.h"
#include "connectsocket.h"
#include "listenserver.h"
#include "Login/login.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private:

private slots:
    void on_m_twFriendList_cellClicked(int row, int column);
    void on_m_twFriendList_itemDoubleClicked(QTableWidgetItem* item);
    void on_m_twFriendList_itemClicked(QTableWidgetItem* item);
    void on_tabWidget_currentChanged(int index);

signals:
    void selectNewFriend(QString name,QString ip,int port);

    ///dispatch the data to the specific module
    void dispatchDataToChat(MSGHeader header,QByteArray data);
    void dispatchDataToIdeaBox(MSGHeader header,QByteArray data);
    void dispatchDataToCalendar(MSGHeader header,QByteArray data);
    void dispatchDataToLogin(MSGHeader header,QByteArray data);

private slots:
    void interpretData(MSGHeader header,QByteArray data); //recive data from
                                                          //socket and interpret
    ///send the client package to server
    void sendPackage(QByteArray package);
    ///cooperation with Login module
    void processShowGUI();

    ///recieve the user list form server
    void receiveUserList(MSGHeader header,QByteArray data);

private:
public:
    Ui::MainWindow *ui;

    ConnectSocket m_ServerConnection;   ///connect to system server

    Chat *m_pChat;          ///chat widget
    IdeaBox *m_pIdeaBox;    ///ideabox widget
    Calendar *m_pCalendar;  ///calendar widget

    MSGHeader m_header;     ///header,protocol
    QByteArray m_data;      ///message body,the actrul data
};

#endif // MAINWINDOW_H
